<!DOCTYPE html>
<html>
<include file="Public:header" />
<link href="__ACSS__/dialog.css" rel="stylesheet">
<link href="__ACSS__/plugins/validform/validform.css" rel="stylesheet">
<link href="__ACSS__/plugins/summernote/summernote.css" rel="stylesheet">
<link href="__ACSS__/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<style>
	.form-control{ padding-left:5px;}
	.upload-warp{ position:relative;}
	.upload-btn{ position:absolute; top:0; right:0; border-radius:0;}
	
	.file-preview {border:1px solid #ddd; padding:5px; width:100%; margin-bottom:5px;}
	.file-preview-frame{ margin:8px; border:1px solid #ddd; box-shadow:1px 1px 5px 0px #a2958a; padding:6px; float:left; text-align:center; vertical-align:middle;}
	.file-preview-frame .btn{ float:right; margin-top:5px;}
	.file-preview-text{ color:#428bca; font-size:11px; text-align:center;}
	#mapContainer{width:100%; height:400px;}
	.clockpicker{ width:46%; float:left;}
	.clockpicker-addon{ width:8%; height:34px; line-height:34px; text-align:center; float:left;}
	.modal-backdrop{ display:none;}
</style>
  <body>
	  <div class="wrapper wrapper-content animated fadeInRight">
	  	<form role="form" class="form" action="__URL__/update">
			<input type="hidden" name="id" value="<{$vo.id}>">
			<input type="hidden" name="update_time" value="<?php echo time();?>">
			<div class="form-group">
				<label class="col-sm-2 control-label">类型：</label>
				<div class="col-sm-10">
				    <select class="form-control"datatype="*" name=""type_code"">
						<option <if condition="$vo.type_code eq 1"> selected</if> value="1">新闻动态</option>
						<option <if condition="$vo.type_code eq 2"> selected</if> value="2">美食资讯</option>
				    </select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">标题：</label>
				<div class="col-sm-10">
					<input type="text" datatype="*" name="title" class="form-control" value="<{$vo.title}>"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">主图：</label>
				<div class="col-sm-10">
					<div class="file-preview">
					    <div class="file-preview-thumbnails" data-num="1">
							<div class="file-preview-frame">
								<span class="file-preview-image"><img style="width:150px;" src="__IMGROOT__<{$vo.photo}>" rel="<{$vo.photo}>" ref="<{$vo.photo}>" class="file-preview-image"></span>
								<div class="clearfix"></div><button onclick="delPhoto(this)" type="button" class="btn btn-xs btn-white"><i class="glyphicon glyphicon-trash text-danger"></i></button>
							</div>
						</div>
					    <div class="clearfix"></div>
					</div>
					<div class="upload-warp">
	                	<input class="form-control localname" type="text" placeholder="尺寸为320px*320px 50kb左右" datatype="*" nullmsg="请上传图片" value="<{$vo.photo}>" errormsg="请上传图片" readonly="readonly">
	                	<button type="button" onclick="doUpload(this)" class="btn btn-primary upload-btn"><i class="glyphicon glyphicon-folder-open"></i>&nbsp;&nbsp;选择&nbsp;...</button>
	               		<input type="hidden" name="photo" value="<{$vo.photo}>" class="head_picture"/>
               		</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">简介：</label>
				<div class="col-sm-10">
					<input type="text" datatype="*1-255" name="desc" class="form-control" value="<{$vo.desc}>"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">内容：</label>
				<div class="col-sm-10">
					<div class="summernote"><{$vo.content}></div>
					<div class="clearfix"></div>
					<textarea class="form-control hide" datatype="*" id="content-input" name="content" rows="3"></textarea>
					<span class="Validform_checktip"></span>
				</div>
			</div>
			<div class="clearfix">
				<button type="submit" id="submit" class="btn btn-success btn-block">提交</button>
				<button type="reset" id="reset2" class="btn btn-success btn-block hidden">重置</button>
			</div>
		</form>
	  </div>
  </body>
<!-- 全局js -->
<include file="Public:foot" />
<script src="__AJSPLUGINS__/validform/Validform_v5.3.2_min.js"></script>
<!-- SUMMERNOTE -->
<script src="__AJSPLUGINS__/summernote/summernote.min.js"></script>
<script src="__AJSPLUGINS__/summernote/summernote-zh-CN.js"></script>
<!-- Uploader -->
<script type="text/javascript" src="__AJS__/jquery.upload.js"></script>
<script>
$(function(){
	$('.summernote').summernote({
		height: 200,
        lang: 'zh-CN',
        onImageUpload: function(files, editor, $editable) {
        	sendFile(files[0],editor,$editable);
        }
    });
	$("#reset2").click();
	var index = parent.layer.getFrameIndex(window.name);
	var form = $(".form").Validform({
		tiptype:4,
		ajaxPost:true,
		beforeCheck:function(curform){
			$("#content-input").val($('.summernote').code());
		},
		callback:function(data){
			if(data.status == 1) {
				window.parent.layer.msg(data.info);
				window.parent.$('#table_list').trigger("reloadGrid");
			}else{
				window.parent.layer.msg(data.info);
			}
			parent.layer.close(index);
		}
	});
})

//summernote上传图片
function sendFile(file, editor, $editable){
	var name = new Date().getTime();
	//name是文件名，自己随意定义
	data = new FormData();
	data.append("file", file);
	$.ajax({
		type: "POST",
		url: "__URL__/uploadImgForEditor",
		data: data,
		cache: false,
		contentType: false,
		processData: false,
		success: function(data) {
			var data = eval("("+data+")");
			var url = data[0]['webRoot'] + data[0]['savepath'] + data[0]['savename'];
			editor.insertImage($editable, url);
		},
		error:function(){
			layer.msg("上传失败");
		}
	});
}
</script>
<script>
function doUpload(t,type) {//type:1为单图上传 type:2为多图上传
	$.upload({
	        url: '__URL__/uploadImg',
	        fileName: 'filedata',
	        dataType: 'json',
	        acceptType:'image/jpeg,image/png',
	        params: {name: 'head_picture'},
	        onSend: function() {
	        	return true;
	        },
	        // 上传之后回调
	        onComplate: function(data) {
	        	if(data.err.length == 0){
	        		var url = data.msg.url;
	        		if($(t).parents(".form-group").find(".file-preview-thumbnails").attr("data-num") == 1) {
	        			$(t).parents(".form-group").find(".file-preview-thumbnails").html('<div class="file-preview-frame"><span class="file-preview-image"><img style="width:150px;" class="file-preview-image" ref="'+ data.msg.localname  +'" rel="'+ url  +'" src=__IMGROOT__'+ url +'></span><div class="clearfix"></div><button class="btn btn-xs btn-white" type="button" onclick="delPhoto(this)"><i class="glyphicon glyphicon-trash text-danger"></i></button></div>');
	        		}else if($(t).parents(".form-group").find(".file-preview-thumbnails").attr("data-num") > 1) {
	        			$(t).parents(".form-group").find(".file-preview-thumbnails").append('<div class="file-preview-frame"><span class="file-preview-image"><img style="width:150px;" class="file-preview-image" ref="'+ data.msg.localname  +'" rel="'+ url  +'" src=__IMGROOT__'+ url +'></span><div class="clearfix"></div><button class="btn btn-xs btn-white" type="button" onclick="delPhoto(this)"><i class="glyphicon glyphicon-trash text-danger"></i></button></div>');
	        		}
	        		initPhoto();
	        	}else{
	        		layer.alert(data.err);
	        	}
	        }
	});
}
//重新绘制图片尺寸
function resizeView() {
	/*
	if($(".file-preview-image").width() > $(".file-preview-thumbnails").width()) {
		$(".file-preview-image").width($(".file-preview-thumbnails").width());
	}else{
		$(".file-preview-image").width("100%");
	}
	*/
}

//删除图片
function delPhoto(t) {
	layer.confirm('确定执行？', function(index){
		$(t).parents(".file-preview-frame").remove();
		initPhoto();
	    layer.close(index);
	});
}

function initPhoto() {
	//上传张数上限操作
	$(".file-preview-thumbnails").each(function() {
		if($(this).attr("data-num") <= $(this).find(".file-preview-frame").length) {
			$(this).parents(".col-sm-10").find(".upload-btn").attr("disabled","disabled");
		}else{
			$(this).parents(".col-sm-10").find(".upload-btn").removeAttr("disabled");
		}
		if($(this).find(".file-preview-frame").length == 0) {
			$(this).parents(".file-preview").hide();
		}else{
			$(this).parents(".file-preview").show();
		}
	})
	//初始化图片相应表单属性
	$(".file-preview-thumbnails").each(function() {
		var localname = "";
		var url = "";
		$(this).find("img").each(function(index) {
			if(index == 0) {
				url += $(this).attr("rel");
				localname += $(this).attr("ref");
			}else{
				url += "|" + $(this).attr("rel");
				localname += "|" + $(this).attr("ref");
			}
		})
		$(this).parents(".col-sm-10").find(".localname").val(localname);
		$(this).parents(".col-sm-10").find(".head_picture").val(url);
	})
}

$(function(){
	initPhoto();
	$("#reset2").click();
	var index = parent.layer.getFrameIndex(window.name);
	var form = $(".form").Validform({
		tiptype:4,
		ajaxPost:true,
		callback:function(data){
			if(data.status == 1) {
				window.parent.layer.msg(data.info);
				window.parent.$('#table_list').trigger("reloadGrid");
			}else{
				window.parent.layer.msg(data.info);
			}
			parent.layer.close(index);
		}
	});
})
</script>
</html>